package org.nox.helloseries.server.remoting.transmission;

import java.io.File;

import org.nox.helloseries.server.Launcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TransmissionConnector
{
    private static final Logger LOG = LoggerFactory.getLogger( Launcher.class );

    private static final String BASE_CMD = "transmission-remote --auth=admin:_admin.+1 -a ";

    public boolean send( File file )
    {
        try
        {
            LOG.debug( "Téléchargement via transmission remote du fichier : " + file.getAbsolutePath() );
            try
            {
                LOG.info( "Execution de la commande : " + BASE_CMD + file.getAbsolutePath() );
                Runtime r = Runtime.getRuntime();
                Process p = r.exec( BASE_CMD + file.getAbsolutePath() );
                p.waitFor();// si l'application doit attendre a ce que ce process fini
                return true;
            }
            catch ( Exception e )
            {
                LOG.error( e.getMessage() );
            }

        }

        catch ( Exception e )
        {
            LOG.error( e.getMessage() );
            return false;
        }
        return false;
    }
}
